package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.MessageBean;
import com.project.config.MybatisConfig;
import com.project.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;


@RequestMapping("mess")
@Controller
public class MessController {

    @Autowired
    private IMessageService service;

    @RequestMapping("findByItem")
    public String findByItem(@RequestParam(value = "pageNO",defaultValue = "1") int pageNO,
                             String name, String job, HttpServletRequest request){
        PageInfo<MessageBean> info = service.findByItem(pageNO,name,job);
        request.setAttribute("name",name);
        request.setAttribute("job",job);
        request.setAttribute("info",info);

        return "/html/message.html";
    }

    @RequestMapping("add")
    public String addMess(MessageBean mess){
        service.add(mess);

        return "redirect:/mess/findByItem";
    }

    @RequestMapping("del")
    public String delMess(int id){
        service.del(id);
        return "redirect:/mess/findByItem";
    }

    @RequestMapping("findById")
    public String findById(int id,HttpServletRequest request){
        MessageBean messageBean = service.findById(id);
        request.setAttribute("message",messageBean);

        return "html/update.html";
    }

    @RequestMapping("update")
    public String update(int id,String phone){
        service.update(id,phone);
        return "redirect:/mess/findByItem";
    }
}
